local jLootz = jLootz
local lib = jLootz:GetModule("Group")

local confirm

local function ActivateChildren(enable, id, type)
	for _, frame in pairs(lib.frames) do
		if enable then
			frame.pass:Enable()
			frame.need:Enable()
			frame.greed:Enable()
			if frame.slot == id then
				if type == 1 then
					frame.need:UnlockHighlight()
				elseif type == 2 then
					frame.greed:UnlockHighlight()
				end
			end
		else
			frame.pass:Disable()
			frame.need:Disable()
			frame.greed:Disable()
			if frame.slot == id then
				if type == 1 then
					frame.need:LockHighlight()
				elseif type == 2 then
					frame.greed:LockHighlight()
				end
			end
		end
	end
end

function lib:ShowConfirm(frame, id, type)
	if confirm == nil then
		confirm = jLootz:GetConfirmModule() or false
	end
	if not confirm then
		local _, name, _, quality = GetLootRollItemInfo(id)
		local dialog = StaticPopup_Show("CONFIRM_LOOT_ROLL", ITEM_QUALITY_COLORS[quality].hex..name.."|r");
		if dialog then
			dialog.data = id
			dialog.data2 = type
		end
	else
		confirm:SetArguments("Confirm", ConfirmLootRoll, ActivateChildren, id, type)
		confirm:Show(frame)
	end
end

function lib:HideConfirm()
	if not confirm then
		StaticPopup_Hide("CONFIRM_LOOT_ROLL")
	else
		confirm:Hide()
	end
end
